package com.zhuangfei.hpuhelper.tools;

import android.content.Context;

import com.hpu.bean.RoomBean;
import com.zhuangfei.hpuhelper.bean.ElectricCharge;
import com.zhuangfei.hpuhelper.bean.PhoneBean;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * 加载数据
 * @author Administrator
 *
 */
public class ElectricChargeTools {

	/**
	 * 静态方法，用于从文本中加载
	 * @return
	 */
	public static List<ElectricCharge> load(Context context,String file){
		List<ElectricCharge> charges = new ArrayList<>();
		try {
			InputStreamReader is=new InputStreamReader(context.getAssets().open(file), "UTF-8");
			BufferedReader reader = new BufferedReader(is);
			String lineTxt = null;
			while ((lineTxt = reader.readLine()) != null) {
				if(lineTxt.indexOf(";")!=-1) {
					String[] arr = lineTxt.split(";");
					charges.add(new ElectricCharge(arr[0], arr[1]));
				}
				
			}
			reader.close();
			is.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return charges;
	}
}
